% PL_test_denoising performs denoising on a test image and displays the 
% result. It is intended to show the usage of the function PL_denoising.
% The option 'PL' specifies the regularization to be "Parallel Level Sets"
% proposed in [1].
%
% See also: PL_denoising
%
% [1] M. J. Ehrhardt and S. Arridge, 
%     Vector-Valued Image Processing by Parallel Level Sets, 
%     IEEE Transactions on Image Processing (to appear), 2013
%
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------

%% TOGGLE comments to switch between examples.

% [solution, time, data, ground_truth] = PL_denoising('bugs', '05', 'PL', 1.63, 4.30);
% [solution, time, data, ground_truth] = PL_denoising('bugs', '35', 'PL', 3.89, 10.64);
% [solution, time, data, ground_truth] = PL_denoising('pyramid', '35', 'PL', 5.00, 12.33);
[solution, time, data, ground_truth] = PL_denoising('leopard', '15', 'PL', 1.04, 12.00);
% [solution, time, data, ground_truth] = PL_denoising('leopard', '25', 'PL', 1.51, 12.57);

display([' --- elapsed time: ' num2str(time) 's']);

%% Plot results - NO NEED TO EDIT AFTER THIS LINE

% plot ground truth, data and solution in one figure with some statistics
% in the titles. These are the peak signal-to-noise ratio (PSNR) and the
% structural similarity measure (SSIM).
figure(1);
subplot(221); Plot_image(ground_truth); title('ground truth');

title_string = sprintf('data, PSNR:%3.2fdB, SSIM:%3.2f%%', ...
    PSNR(ground_truth, data), SSIM(ground_truth, data)*100);
subplot(223); Plot_image(data); title(title_string);

title_string = sprintf('reconstruction, PSNR: %3.2fdB, SSIM: %3.2f%%', ...
    PSNR(ground_truth, solution), SSIM(ground_truth, solution)*100);
subplot(224); Plot_image(solution); title(title_string);

% The second plot shows the three images combined in one image.
figure(2);
i = Struct2im(ground_truth);
d = Struct2im(data);
s = Struct2im(solution);

N1 = round(1./3 * size(i,2));
N2 = round(2./3 * size(i,2));

i(:,N1+1:N2,:) = d(:,N1+1:N2,:);
i(:,N2+1:end,:) = s(:,N2+1:end,:);

image(i./255.); axis image off;
text(round(1./6 * size(i,2)), 25, ['\fontsize{20}\color{red}ground truth'], 'HorizontalAlignment', 'center');
text(round(3./6 * size(i,2)), 25, ['\fontsize{20}\color{red}data'], 'HorizontalAlignment', 'center');
text(round(5./6 * size(i,2)), 25, ['\fontsize{20}\color{red}reconstruction'], 'HorizontalAlignment', 'center');